import logging

import requests

from api.api_approve_trust import ApiApproveTrust
from api.api_register_login import ApiRegisterLogin
from tool import common_assert


class TestApproveTrust:
    # 初始化
    def setup(self):
        # 获取session对象
        self.session = requests.session()
        # 获取class ApiApproveTrust 实例对象
        self.api = ApiApproveTrust(self.session)
        # 获取 ApiRegisterLogin 登录对象
        self.login = ApiRegisterLogin(self.session).api_login()

    # 结束session
    def teardown(self):
        self.session.close()

    # 1，认证接口 测试
    def test01_approve(self, expect_json="提交成功"):
        try:
            result = self.api.api_approve()
            common_assert(result, expect_json=expect_json)
        except Exception as e:
            logging.error(e)
            raise

    # 2，查询认证接口 测试
    def test02_approve_status(self, expect_text="1111"):
        try:
            # 调用查询接口
            result = self.api.app_approve_status()
            common_assert(result, expect_text=expect_text)
        except Exception as e:
            logging.error(e)
            raise

    # 3，后台开户接口 测试
    def test03_trust(self, expect_text="from"):
        try:
            # 调用查询接口
            result = self.api.api_trust()
            common_assert(result, expect_text=expect_text)
        except Exception as e:
            logging.error(e)
            raise
